/**
 * @author hoang.pt
 * @version $Id: Thread4.java 175 2010-09-10 03:50:49Z phantichhoang $
 */

package test1.problem2;


/**
 * Thread 4
 * @author hoang.pt
 */
public class Thread4 implements Runnable{
	
	/**
	 * @var Thread
	 */
    Thread t;

    /**
     * @var Data
     */
    Data d;

    /**
     * constructor
     */
    public Thread4(Data d) {

        //use data with thread 1
        this.d = d;

        //init thread 2
        t = new Thread(this);
        t.start();
    }

    
    /**
     * 
     */
    public void run()
    {

       //run forever
       while (true) {
            //synchronise
           synchronized(d) {

               if (d.flag) {
                   //display name
                   d.displayName();

                   //change flag
                   d.flag = false;
               }
           }
       }
    }
}
